<template>
  <div class="container">
    <div>
      <el-form ref="form" :model="form">
        <!-- <el-form-item label="考核任务名称：" label-width="110px">
          <el-input
            v-model="form.NAME"
            placeholder="请输入"
            class="handle-input mr10"
          ></el-input>
        </el-form-item> -->
        <el-form-item label="考核单位：" label-width="110px">
          <el-select v-model="form.DW" placeholder="请选择" @change="getObjectList">
            <el-option
              v-for="item in unitData"
              :key="item.CLIENT_NO"
              :label="item.UNITNAME"
              :value="item.CLIENT_NO"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核日期：" label-width="110px">
          <el-date-picker
            v-model="form.startDate"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="考核类型：" label-width="110px">
          <el-select v-model="form.LX" placeholder="请选择" @change="getObjectList()">
            <el-option
              v-for="item in typeData"
              :key="item.ID"
              :label="item.TYPENAME"
              :value="item.ID"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核项目：" label-width="110px">
          <el-select v-model="form.XM" placeholder="请选择" @change="getObjectTypelList(),getStandardList()">
            <el-option
              v-for="item in itemData"
              :key="item.ID"
              :label="item.ITEMNAME"
              :value="item.ID"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核对象类型：" label-width="110px">
          <el-select v-model="form.DLX" placeholder="请选择" @change="getLevelList(),getStandardList()">
            <el-option
              v-for="item in objectTypeData"
              :key="item.ID"
              :label="item.OBJECTTYPE"
              :value="item.ID"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目等级：" label-width="110px">
          <el-select v-model="form.DJ" placeholder="请选择" @change="getObjectList()">
            <el-option
              v-for="item in levelData"
              :key="item.ITEMLEVEL"
              :label="item.ITEMLEVEL"
              :value="item.ITEMLEVEL"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核标准：" label-width="110px">
          <el-select v-model="form.BZ" placeholder="请选择" @change="getObjectList()">
            <el-option
              v-for="item in standardData"
              :key="item.BH"
              :label="item.TITLE"
              :value="item.BH"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核对象：" label-width="110px">
          <el-select v-model="form.DX" placeholder="请选择"multiple 
            collapse-tags>
            <el-option
              v-for="item in objectData"
              :key="item.ID"
              :label="item.NAME"
              :value="item.ID"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-row type="flex" justify="center">
        <el-col :span="24"
          ><div align="center">
            <el-button
              type="primary"
              @click="saveAdd()"
              style="width: 100%; margin-bottom: 18px"
            >
              考 核 任 务 生 成</el-button
            >
          </div></el-col
        >
      </el-row>
    </div>
    <!-- <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="typeData3.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div> -->
  </div>
</template>
<script>
import '@/assets/css/common.css'

import export2Excel from '@/utils/exportExcel/index.js'
import OSS from 'ali-oss';
import { time } from 'echarts';
export default {
  data () {

    return {
      startDate: '',
      typeData: [],
      standardData: [],
      unitData: [],
      itemData: [],
      objectData: [],
      objectTypeData: [],
      levelData: [],
      checkList1: ['道路机扫-道路'],
      checkList2: ['考核覆盖率'],
      checkList3: '是',
      clientData: [],
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      originalData: [],
      tableData: [],
      select: {
        CPH: ''
      },
      isVisibleEdit: false,
      input: 1,
      inputPlaceholder: '请输入数量',
      queryType: '',
      queryTypeList: [{
        value: 1,
        label: '全部抽样'
      }, {
        value: 2,
        label: '条件抽样'
        // }, {
        //   value: 3,
        //   label: '按比例抽取'
        // // }, {
        // //   value: 3,
        // //   label: '整群抽样'
        // // }, {
        // //   value: 4,
        // //   label: '机械抽样'
        }, {
          value: 3,
          label: '地图绘制范围抽样'
      }],
      labelwidth: 100,
      addDialogTitle: '',
      form: {
        WaterCPH: "",
        WaterTime: "",
        CreateTime: "",
        WaterNumber: "",
        WaterLocation: "",
        WaterCphType: "",
        WaterPeople: "",
        WaterPeopleID: "",
      },
      tableData: [],
      contentTags: ['道路机扫-道路', '环卫作业公司', '公厕'],
      contentTags2: ['考核覆盖率', '黑名单', '上次考核不达标'],
      conditionTags: ['按数量抽取', '按比例抽取', '按地图绘制范围'],
      inputVisible: false,
      inputValue: '',
      isRandom: false,
      isRandomInput: ''
    }
  },
  created () {

    // if (localStorage.getItem('CTYPE') == '0') {
    //   this.rolelevel.shift()
    // } else if (localStorage.getItem('CTYPE') != '-1') {
    //   this.rolelevel = []
    // }
    // this.getClientRoleList()
  },
  mounted () {
    this.getUnitList()
    this.getTypeList()
    this.getItemList()
    // this.getObjectList()
    // this.getClientRoleList()
    // this.originalData = data
    // this.screeningData()
  },
  methods: {
    
    // 获取考核单位列表
    async getUnitList () {
      var url = 'Assess/GetUnit_Assess?UNITNAME='
      let { data } = await this.$Http.get(url)
      this.unitData = data
    },
    // 获取考核类型列表
    async getTypeList () {
      var url = 'Assess/GetCheckType_Assess?TYPENAME='
      let { data } = await this.$Http.get(url)
      this.typeData = data
    },
    // 获取考核项目列表
    async getItemList () {
      var url = 'Assess/GetCheckItem_Assess?KEY='
      let { data } = await this.$Http.get(url)
      this.itemData = data
    },
    // 获取考核对象类型
    async getObjectTypelList () {
      var url = 'Assess/GetObjectType_Assess?ITEMID=' + this.form.XM + '&OBJECTTYPE='
      let { data } = await this.$Http.get(url)
      this.objectTypeData = data
    },
    // 获取考核项目等级列表
    async getLevelList () {
      var url = 'Assess/GetItemLevelList_Assess?CLIENT_NO='+ localStorage.getItem('CLIENT_NO') + '&ITEMID=' + this.form.XM + '&OBJECTTYPE=' + this.form.DLX
      let { data } = await this.$Http.get(url)
      this.levelData = data
    },
    // 获取考核标准列表
    async getStandardList () {
      var url = 'Assess/GetStandardDetail_Assess?ITEMID=' + this.form.XM + '&OBJECTTYPEID=' + this.form.DLX + '&KEY='
      let { data } = await this.$Http.get(url)
      this.standardData = data
    },
    // 获取考核对象列表
    async getObjectList () {
      var url = 'Assess/GetItemObjectList_Assess?CLIENT_NO=' + this.form.DW +'&ITEMID=' + this.form.XM + '&OBJECTTYPE=' + this.form.DLX + '&ITEMLEVEL=' + this.form.DJ
      //  + localStorage.getItem('CLIENT_NO') + '&StartTime=' + this.form.STARTDATE + '&EndTime=' + this.form.ENDDATE
      let { data } = await this.$Http.get(url)
      this.objectData = data
    },
    
    // 导出Excel
    exportExcel () {
      let excelName = '考勤时间信息列表'
      const tHeader = ['编号', '人员姓名', '所属班组', '上午上班时间', '上午下班时间', '下午上班时间', '下午下班时间']
      const filterVal = ['VID', '人员姓名', '所属班组', '上午上班时间', '上午下班时间', '下午上班时间', '下午下班时间']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },

    // 生成考核任务
    async saveAdd () {
      var str = '';
      this.form.DX.forEach(element => {
        str = str + element + ','
      });
      str = str.substring(0, str.length - 1);
      this.form.DID = str
      this.$axios({
        url: 'Assess/SaveTaskInfo_Assess',
        method: 'post',
        data: {
          ID: '0',
          WORKDATE: this.form.startDate,
          CHECKTYPEID: this.form.LX,
          CHECKITEMID: this.form.XM,
          CHECKOBJECTTYPEID: this.form.DLX,
          ITEMLEVEL: this.form.DJ,
          CLIENT_NO: this.form.DW,
          RANDOMTYPE: '录入',
          LEVEL: this.form.DJ,
          STANDARDIDS: this.form.BZ,
          OBJECTIDS: this.form.DID,
          CREATENO: localStorage.getItem('CLIENT_NO'),
          INSYSTEMID: '0',
        },

      }).then((res) => {
        if (res.data.IsSucess) {
          this.$message.success('考核任务生成成功');
        } else {
          this.$message.error('考核任务生成失败');
        }
      })

    },
    // 模糊查询
    screeningData () {
      this.tableData = this.originalData
      if (this.select.CPH) this.tableData = this.tableData.filter(item => item.CPH.includes(this.select.CPH))
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getlistdata();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.el-form-item__label {
  text-align: left;
}
/* .el-checkbox {
  color: #fff;
}
.el-checkbox__label {
  color: #fff !important;
} */
.content {
  overflow-y: scroll;
}
.el-col-6 {
  width: 350px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
.el-form-item label {
  width: 80px;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  height: 32px;
  line-height: 30px;
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.aroundtop {
  padding: 10px;
  background-color: #007acc;
  height: 100%;
  border-radius: 5px;
}
.el-icon-speed {
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  height: 30px;
  line-height: 28px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  margin: 10px 20px 10px 20px;
}
</style>